package part3.dip_practise2.first;

/**
 * Created by lie on 2018/4/9.
 * 高层依赖了细节，后续拓展很麻烦
 * 违背了开放封闭原则
 */
public class DeviceService {
    private int deviceType = 0;

    public static final int DEVICE_TYPE_HY = 0;
    public static final int DEVICE_TYPE_LNT = 1;
    private HYDevice hyDevice;
    private LNTDevice lntDevice;

    public DeviceService(int deviceType) {
        this.deviceType = deviceType;
        switch (deviceType){
            case DEVICE_TYPE_HY:
                hyDevice = new HYDevice();
                break;
            case DEVICE_TYPE_LNT:
                lntDevice = new LNTDevice();
                break;
            default:
                hyDevice = new HYDevice();
                break;
        }
    }

    public void loginDevice(){
        switch (deviceType){
            case DEVICE_TYPE_LNT:
                lntDevice.login();
                break;
            default:
                hyDevice.login();
                break;
        }
    }

    public void logoutDevice(){
        switch (deviceType){
            case DEVICE_TYPE_LNT:
                lntDevice.logOut();
                break;
            default:
                hyDevice.logOut();
                break;
        }
    }

}
